/*
 * @Author: szx
 * @Date: 2022-06-21 14:44:02
 * @LastEditTime: 2022-06-21 14:52:38
 * @Description:
 * @FilePath: \leetcode\1000-1099\1089\1089.js
 */
/**
 * @param {number[]} arr
 * @return {void} Do not return anything, modify arr in-place instead.
 */
var duplicateZeros = function (arr) {
    const len = arr.length;
    let tmp = 0,
        i = 0;
    for (; i < len; i++) {
        if (arr[i] === 0) tmp++;
        tmp++;
        if (tmp >= len) break;
    }
    if (i == len) return arr;
    let j = len - 1;
    if (tmp > len) {
        arr[j] = 0;
        i--;
        j--;
    }
    while (j >= 0) {
        if (arr[i] == 0) arr[j--] = 0;
        arr[j--] = arr[i--];
    }
    return arr;
};
